package com.zmj.demo.restclient;

import com.zmj.framework.response.Result;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Component
@FeignClient(name = "authClient", url = "http://localhost:8080/")
public interface AuthClient {

    @CircuitBreaker(name = "simple", fallbackMethod = "helloFallback")
    @RequestMapping(method = RequestMethod.GET, value = "/v1/hello")
    Result getException();

    default Result helloFallback( Throwable exc) {
        exc.printStackTrace();
        return Result.fail(exc.getMessage());
    }
}